package com.metaera.app.ui.adapters;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.HotSearchResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;

import androidx.annotation.NonNull;

public class SearchHotAdapter extends BaseQuickAdapter<HotSearchResponse, BaseViewHolder> {

    public SearchHotAdapter() {
        super(R.layout.item_hot_search);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            context.startActivity(ArticleDetailsActivity.newInstance(context, getItem(position).getId()));
        });

    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, HotSearchResponse item) {

        holder.setText(R.id.tv_number, String.valueOf(getItemPosition(item) + 1))
                .setBackgroundResource(R.id.rl_num, get(item))
                .setText(R.id.tv_hot_title, item.getTitle());
    }


    private int get(HotSearchResponse item){
        switch (getItemPosition(item)){
            case 0:
                return R.drawable.icon_search_hot_1;
            case 1:
                return R.drawable.icon_search_hot_2;
            case 2:
                return R.drawable.icon_search_hot_3;
            default:
                return R.drawable.icon_search_hot_normal;
        }
    }
}
